package com.spider.silence.main;

import com.spider.silence.downloader.KaiDiDownLoader;
import com.spider.silence.env.job.KaiDiEnvInitJob;
import com.spider.silence.pool.KaiDiDownLoaderPool;

import com.spider.silence.utils.CenterExecutorUtil;
import com.spider.silence.utils.PropertiesUtil;
import com.spider.silence.worker.KaiDiWorker;
import org.apache.log4j.PropertyConfigurator;

import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Created by Administrator on 2017/1/9 0009.
 */
public class KaiDiMain {
    public static void main(String[] args) throws Exception {
        PropertyConfigurator.configure( PropertiesUtil.getLogPro());//初始化日志环境
        KaiDiDownLoaderPool downLoaderPool = null;
        KaiDiDownLoader downLoader = null;
        try{
            downLoaderPool = KaiDiDownLoaderPool.getInstance();
            downLoader = downLoaderPool.fetchDownLoader(1000);
            List<String> urlList = downLoader.getUrl();
            //生成任务队列
            downLoader.generateTask(urlList);

        }catch(Exception e){
            e.printStackTrace();
        }finally {
            if(downLoader != null){
                downLoaderPool.releaseDownLoader(downLoader);
            }
        }

        ExecutorService initPool= Executors.newFixedThreadPool(Integer.parseInt(PropertiesUtil.getVal("main.env.runnable.pool.size")));
        initPool.execute(new KaiDiEnvInitJob());



        /*//初始化Worker
        ExecutorService pool =  Executors.newFixedThreadPool(Integer.valueOf(PropertiesUtil.getVal("main.woker.size")));
        for(int i = 0; i < Integer.valueOf(PropertiesUtil.getVal("KaiDi.WorkerCount")); i++){
            CenterExecutorUtil.execute(new KaiDiWorker());
        }*/

    }
}
